#上传文件

import uuid
import cgi, os
from werkzeug.utils import secure_filename
import xlrd

ALLOW_EXTENSIONS = set(['xls', 'xlsx', 'csv'])

def file_upload(file):
    filename = secure_filename(file.filename)
    if file and allowed_file(file.filename):
        file_name = str(uuid.uuid4()) + '.' + filename.rsplit('.', 1)[1]

        UPLOAD_FOLDER = 'upload'
        if not os.path.exists(UPLOAD_FOLDER):
            os.makedirs(UPLOAD_FOLDER)
        else:
            pass
        file.save(os.path.join(UPLOAD_FOLDER,file_name))
        base_path = os.getcwd()
        slash = '\\'
        file_path = UPLOAD_FOLDER + slash + file_name
        return file_path
    else:
        return ''

def file_upload2(file):
    filename = secure_filename(file.filename)
    if file and allowed_file(file.filename):
        # file_name = str(uuid.uuid4()) + '.' + filename.rsplit('.', 1)[1]
        file_name = file.filename
        UPLOAD_FOLDER = 'upload'
        if not os.path.exists(UPLOAD_FOLDER):
            os.makedirs(UPLOAD_FOLDER)
        else:
            pass
        file.save(os.path.join(UPLOAD_FOLDER,file_name))
        base_path = os.getcwd()
        slash = '\\'
        file_path = UPLOAD_FOLDER + slash + file_name
        return file_path
    else:
        return ''
        
# 判断文件后缀是否在列表中
def allowed_file(filename):
    return '.' in filename and \
            filename.rsplit('.', 1)[1] in ALLOW_EXTENSIONS

def excelData(file_path):
    book = xlrd.open_workbook(file_path)
